<?php
include "includeFiles.php";

if(!empty($id)){
	if($action == "add"){
		$sql = "select * from hy_b_sys_products where SysProductsID='".$id."'";
		$objDb->query($sql);
		$row = $objDb->get_data();
		if(!$row){
		    $objBase->popup('该产品已下库！');
			exit;
		} else {
			$pname         = $row[0]['ProductName'];
			$productCateID = $row[0]['CateID'];
		}
		$sql = " select * from hy_member_Favorites where productID='".$id."' and memberID='".$_SESSION["user_id"]."'";
		$objDb->query($sql);
		$row = $objDb->get_data();
		if($row){
    		$objBase->popup('您已经收藏了此产品!');
			exit;
		}
		$strtime = date("Y-m-d H:i:s",time());
		
		$arr = array(
		  'memberID'      => $_SESSION['user_id'],
		  'productID'     => $id,
		  'productName'   => $pname,
		  'productCateID' => $productCateID,
		  'createdate'    => $strtime,
		);

		$sql    = $hb->insert('hy_member_Favorites',$arr);
		$result = $objDb->query($sql);
		if($result){
    		$objBase->popup('收藏成功!');
			exit;
		} else {
			$objBase->popup('收藏失败，请重试!');
			exit;
		}
	} else if($action == "del"){
		$sql = "delete from hy_member_Favorites where id=$id";
		$result = $objDb->query($sql);
		if($result){
		    $objBase->popup('删除成功!');
			exit;
		} else {
		    $objBase->popup('删除失败，请重试!');
			exit;
		}
	}
}

?>
  
